<template>
  <el-table ref="tables" v-loading="loading" border :data="orderList" @selection-change="handleSelectionChange"
    	 :default-sort="defaultSort" @sort-change="handleSortChange" :height="bigTableData">
      <el-table-column type="selection" width="55" align="center" fixed="left"/>
      <el-table-column label="订单编号" align="center" prop="orderNo" :show-overflow-tooltip="true" min-width="150"/>
      <el-table-column label="客户ID" align="center" prop="customerId" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="客户签约类型" align="center" prop="customerSignedType" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="产品在保状态" align="center" prop="productInServer" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="服务类型ID" align="center" prop="serverTypeId" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="服务类型名称" align="center" prop="serverTypeName" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="问题类型ID" align="center" prop="problemTypeId" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="问题类型名称" align="center" prop="problemTypeName" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="客户姓名" align="center" prop="customeName" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="客户手机号" align="center" prop="customeMobile" :show-overflow-tooltip="true" min-width="120"/>
      <el-table-column label="产品类型ID" align="center" prop="productCategoryId" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="产品类型名称" align="center" prop="productCategoryName" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="客户产品ID" align="center" prop="customerProductId" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="客户产品名称" align="center" prop="customerProductName" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="客户产品型号" align="center" prop="customerProductModeNo" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="客户产品质保期至" align="center" prop="customerProductExpireDate" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.customerProductExpireDate, '{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="客户门店ID" align="center" prop="customerStoreId" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="客户门店名称" align="center" prop="customerStoreName" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="上门时间" align="center" prop="onsiteDate" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.onsiteDate, '{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="应付金额" align="center" prop="payableAmount" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="实付金额" align="center" prop="paidAmount" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="付款时间" align="center" prop="payTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.payTime, '{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="客户地址ID" align="center" prop="customeAddressId" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="联系人" align="center" prop="contactName" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="联系方式" align="center" prop="contactMobile" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="省ID" align="center" prop="provinceId" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="省名" align="center" prop="provinceName" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="市ID" align="center" prop="cityId" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="市名" align="center" prop="cityName" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="区ID" align="center" prop="districtId" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="区名" align="center" prop="districtName" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="详细地址" align="center" prop="address" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="纬度" align="center" prop="latitude" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="经度" align="center" prop="longitude" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="指派工程师" align="center" prop="assignEngineerId" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="指派时间" align="center" prop="assignTime" width="160">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.assignTime, '{y}-{m}-{d} {h}:{i}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="客户端显示(1是0否)" align="center" prop="isShowCustomer" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="师傅端显示(1是0否)" align="center" prop="isShowEngineer" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="运营端显示(1是0否)" align="center" prop="isShowOperate" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="服务状态" align="center" prop="serverState" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="订单状态" align="center" prop="status" :show-overflow-tooltip="true" min-width="100"/>
      <el-table-column label="操作" align="center" fixed="right" width="180" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-view"
            @click="handleDetail(scope.row)" v-hasPermi="['vanger:order:query']">详情</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit"
            @click="handleUpdate(scope.row)" v-hasPermi="['vanger:order:edit']">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete"
            @click="handleDelete(scope.row)" v-hasPermi="['vanger:order:remove']">删除</el-button>
        </template>
      </el-table-column>
    </el-table>
</template>

<script>
import { listOrder, listUnion, getOrder, getInfoUnion, delOrder, addOrder, updateOrder, exportOrder } from "@/api/vanger/order";

export default {
  name: "Order",
  data() {
    return {
      // 表格高度
      bigTableData:'',
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // vorder表格数据
      orderList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查看详情
      showDetail: false,
      // 默认排序
      defaultSort: {prop: 'createTime', order: 'descending'},
      // 查询参数
      queryParams: {
        params: {},
        pageNum: 1,
        pageSize: 10,
        orderNo: null,
        customerId: null,
        customerSignedType: null,
        productInServer: null,
        serverTypeId: null,
        serverTypeName: null,
        problemTypeId: null,
        problemTypeName: null,
        customeName: null,
        customeMobile: null,
        productCategoryId: null,
        productCategoryName: null,
        customerProductId: null,
        customerProductName: null,
        customerProductModeNo: null,
        customerProductExpireDate: null,
        customerStoreId: null,
        customerStoreName: null,
        onsiteDate: null,
        payableAmount: null,
        paidAmount: null,
        payTime: null,
        customeAddressId: null,
        contactName: null,
        contactMobile: null,
        provinceId: null,
        provinceName: null,
        cityId: null,
        cityName: null,
        districtId: null,
        districtName: null,
        address: null,
        latitude: null,
        longitude: null,
        assignEngineerId: null,
        assignTime: null,
        isShowCustomer: null,
        isShowEngineer: null,
        isShowOperate: null,
        serverState: null,
        status: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        id: [
          { required: true, message: "ID不能为空", trigger: "blur" }
        ],
      }

    };
  },
  created() {
    this.handleSortChange(this.defaultSort);
  },
  mounted() {
    this.bigTableData = document.body.clientHeight - document.getElementsByClassName('searchLeft')[0].offsetHeight - 270 + 'px'
  },
  watch: {
    showSearch() {
      this.$nextTick(function () {
        this.bigTableData = document.body.clientHeight - document.getElementsByClassName('searchLeft')[0].offsetHeight - 270 + 'px'
      })
    }
  },
  methods: {
  
    /** 排序触发事件 */
    handleSortChange(column, prop, order) {
      this.queryParams.orderByColumn = column.prop;
      this.queryParams.isAsc = column.order;
      this.getList();
    },
    /** 查询vorder列表 */
    getList() {
      this.loading = true;
      console.log(this.queryParams);
      listOrder(this.queryParams).then(response => {
        console.log(response);
        this.orderList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.closeDialog()
    },
	// 关闭时设置
    closeDialog() {
      this.open = false;
      this.showDetail = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        orderNo: null,
        customerId: null,
        customerSignedType: null,
        productInServer: null,
        serverTypeId: null,
        serverTypeName: null,
        problemTypeId: null,
        problemTypeName: null,
        customeName: null,
        customeMobile: null,
        productCategoryId: null,
        productCategoryName: null,
        customerProductId: null,
        customerProductName: null,
        customerProductModeNo: null,
        customerProductExpireDate: null,
        customerStoreId: null,
        customerStoreName: null,
        onsiteDate: null,
        payableAmount: null,
        paidAmount: null,
        payTime: null,
        customeAddressId: null,
        contactName: null,
        contactMobile: null,
        provinceId: null,
        provinceName: null,
        cityId: null,
        cityName: null,
        districtId: null,
        districtName: null,
        address: null,
        latitude: null,
        longitude: null,
        assignEngineerId: null,
        assignTime: null,
        isShowCustomer: null,
        isShowEngineer: null,
        isShowOperate: null,
        serverState: null,
        status: 0,
        createTime: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.queryParams.params = {};
      this.resetForm("queryForm");
      // this.$refs.tables.sort(this.defaultSort.prop, this.defaultSort.order)
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加vorder";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getOrder(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改vorder";
      });
    },
    
    /** 查看按钮操作 */
    handleDetail(row) {
      this.reset();
      const id = row.id || this.ids
      getOrder(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "查看vorder";
        this.showDetail = true;
      });
    },
    
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateOrder(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addOrder(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal.confirm('是否确认删除vorder编号为"' + ids + '"的数据项？').then(function() {
        return delOrder(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('vanger/order/export', {
        ...this.queryParams
      }, `order_${new Date().getTime()}.xlsx`)
    }
  }
};
</script>
